/////////////////////////////////////////////////////////////////////////////////////
//The DOM Module 
//Some simple methods interfacing to the DOM
//
ZIP.namespace('Cache');

ZIP.Cache.DOM = function(win) {
    var $win = win,
        _localCache = [],  // used to speed up dom access: getElementBy* is expensive
        $doc = $win.document,
        $id = function(id) {
            var i;
            return ( _localCache[id] ? _localCache[id] : (i=$doc.getElementById(id), _localCache[id]=i, i) );
        },
        $sel = $doc.getElementsByTagName,
        domBody = $doc.getElementsByTagName('body')[0];
        
    
    return {
        id: function(ref) {
            // if ref is in the format #id, then lookup the id in the DOM
            // if ref = "tag" then search the dom by tag and return the collection
            var arr = /(^#)(.*)/i.exec(ref);
            
            if (arr[1] == '#') return $id(arr[2]);
            return $doc.getElementsByTagName(ref);   // return the collection
            
        },
        div: function(css) {
            var e = $doc.createElement('div');
            // set the styles.. e.style.<param> = css.<param>
            if (css) {
                for (var c in css) {
                    e.style[c] = css[c];
                }
            }
        },
        p: function(css) {
            var e = $doc.createElement('p');
            // set the styles.. e.style.<param> = css.<param>
            if (css) {
                for (var c in css) {
                    e.style[c] = css[c];
                }
            }
        },
        span: function(css) {
            var e = $doc.createElement('span');
            // set the styles.. e.style.<param> = css.<param>
            if (css) {
                for (var c in css) {
                    e.style[c] = css[c];
                }
            }
        },
        text: function(text) {
            return $doc.createTextNode(text);
        },
        
        script: function(url) {
            var e = $doc.createElement('script');
        },
        
        setAttributes: function(id, attribs) {
            // attribs: { attrib - value pairs}
            for (var key in attribs) {
                id.setAttribute(key, attribs[key]);
            }
        },
        setStyle: function(id, styles) {
            // styles: { style - value pairs}
            for (var key in styles) {
                id.style[key] = styles[key];
            }
        },
        setCursor: function(c) {  // shotcut helper func
            domBody.cursor = c;
        }
    }   // proto
    
};

//ZIP.System.setUploadCacheStatus('DOM');